<template>
    <el-dialog title="排序"  :close-on-click-modal="false" :visible.sync="show" class="dialog_index"
   :before-close="cancle">
      <el-form >
        <el-form-item label="评论排序：" >
          <el-select  v-model="status" placeholder="评论排序（必填项）" clearable >
            <el-option v-for="item in commentSortList" :key="item.id" :value="item.value" :label="item.label"></el-option>
          </el-select>
         </el-form-item>
      </el-form>
     <span slot="footer" class="dialog-footer">
      <el-button type="search" @click="submitForm">保存</el-button>
      <el-button @click="cancle">取消</el-button>
    </span>
    </el-dialog>
</template>

<script>
import { productCommentSort } from '@/api/product/productComment.js'
export default {
  data () {
    return {
      status: '',
      commentSortList: [
        {value: '1', label: 'S'},
        {value: '2', label: 'A'},
        {value: '3', label: 'B'},
        {value: '4', label: 'C'},
        {value: '5', label: 'D'},
      ],
    }
  },
  props: {
    show: Boolean,
    closeDialog:Function,
    idList: Array
  },
  methods: {
    submitForm () {
      let status = this.validateForm()
      if(status){
        this.subscribe()
      }
    },
    validateForm () {
      let status = true;
      if(!this.status){
        this.$message.error('字段评论排序为必填项！');
        status = false
      }
      return status
    },
    subscribe () {
      let params = {
        id: JSON.stringify(this.idList),
        comment_sort: this.status
      }
      productCommentSort(params).then(res=>{
        if(res.state){
          this.$message.success('保存成功')
          this.cancle()
        }
      })
    },
    cancle(){
      this.$emit('closeDialog')

    },
  }

}
</script>

<style>
.el-dialog__wrapper > .el-dialog .el-dialog__body{
  padding: 24px 48px;
}
</style>